#include "serveraccepter.h"

#include "iserverhandler.h"
#include "iserverwatcher.h"

#include "env.h"
#include "server.h"
#include "connection.h"

namespace app {

ServerAccepter::ServerAccepter(Server& server) : server(server) {
	GetServerWatcher()->AddWatcher(this);	
}

ServerAccepter::~ServerAccepter() {
	GetServerWatcher()->RemoveWatcher(this);	
}

void ServerAccepter::WatcherList(WATCHER_LIST& list) {

}

void ServerAccepter::OnServerAdd(ServerInfo& server_info) {

}

void ServerAccepter::OnServerRemove(ServerInfo& server_info) {

}

bool ServerAccepter::IsServer(net::ISocket* socket) {

}

void ServerAccepter::InitConnection(net::ISocket* socket, Connection* connection) {

}

void ServerAccepter::OnAccept(net::ISocket* socket) {
	//判断该Socket是否合法(已经向ServerManager注册)
	if(IsServer(socket) == false) {
		socket->Close();
		return ;
	}

	//初始化该Connection
	Connection* connection = new Connection(socket);
	IServerHandler* server_handler = server.GetHandler();

	InitConnection(socket, connection);

	//通知应用层
	server_handler->OnInConnection(connection);
}

}
